package cn.itcast.controller;

import cn.hutool.core.collection.CollUtil;
import cn.itcast.entity.Result;
import cn.itcast.service.ReportService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Reference
    private ReportService reportService;

    //查询会员数量折线图
    @RequestMapping("/member/count")
    public Result reportMemberCount(){
        try{
            Map<String, Object> stringObjectMap = reportService.reportMemberCount();
            if(CollUtil.isNotEmpty(stringObjectMap)){
                return new Result(true, "查询成功！", stringObjectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, "查询失败！");
    }

    //查询套餐预约饼图
    @RequestMapping("/setmeals")
    public Result reportSetmeals(){
        try{
            Map<String, Object> stringObjectMap = reportService.reportSetmeals();
            if(CollUtil.isNotEmpty(stringObjectMap)){
                return new Result(true, "查询成功！", stringObjectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, "查询失败！");
    }

    //查询运营数据统计
    @RequestMapping("/business")
    public Result reportBusiness(){
        try{
            Map<String, Object> stringObjectMap = reportService.reportBusiness();
            if(CollUtil.isNotEmpty(stringObjectMap)){
                return new Result(true, "查询成功！", stringObjectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, "查询失败！");
    }

    //查询收入统计柱状图
    @RequestMapping("/income/count")
    public Result reportIncome(){
        try{
            Map<String, Object> stringObjectMap = reportService.reportIncome();
            if(CollUtil.isNotEmpty(stringObjectMap)){
                return new Result(true, "查询成功！", stringObjectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, "查询失败！");
    }

    //查询预约数量和支付数量的折线图
    @RequestMapping("/order/pay")
    public Result reportOrderAndPay(){
        try{
            Map<String, Object> stringObjectMap = reportService.reportOrderAndPay();
            if(CollUtil.isNotEmpty(stringObjectMap)){
                return new Result(true, "查询成功！", stringObjectMap);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(false, "查询失败！");
    }

    //导出excel
    @RequestMapping("/export/business")
    public String exportBusiness(){
        Boolean aBoolean = reportService.exportBusiness();
        if(aBoolean){
            return "导出成功！";
        }
        return "导出失败！请稍后来试";
    }
}
